package com.bjsxt.userscenter.util;

import java.util.Date;
import java.util.Iterator;
import java.util.Map.Entry;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.userscenter.common.util.ConstatFinalUtil;
import com.bjsxt.userscenter.common.util.DateFormatUtil;

@Component("timerUtil")
public class TimerUtil
{
	/**
	 * 定时定点执行此方法
	 */
	public void executTest()
	{
		ConstatFinalUtil.SYS_LOGGER.info(ConstatFinalUtil.ADMINS_MAP.size() + "--前--" + ConstatFinalUtil.ADMINS_MAP);
		DateFormatUtil dateFormatUtil = new DateFormatUtil() ; 
		/* 循环Map移除Token */
		for (Iterator iterator = ConstatFinalUtil.ADMINS_MAP.entrySet().iterator(); iterator.hasNext();)
		{
			Entry me = (Entry) iterator.next();
			
			String key = me.getKey() + "" ; 
			JSONObject adminsJSON = (JSONObject) me.getValue() ;
			String verifyDateStr = adminsJSON.getString("verifyDate");
			/* 1分钟后超时 */
			Date verifyDate = dateFormatUtil.strDateTime(verifyDateStr);
			if(new Date().getTime() - verifyDate.getTime() > 1000 * 60 )
			{
				/* 移除操作 */
				ConstatFinalUtil.ADMINS_MAP.remove(key);
			}
		}
		ConstatFinalUtil.SYS_LOGGER.info(ConstatFinalUtil.ADMINS_MAP.size() + "--后--" + ConstatFinalUtil.ADMINS_MAP);
	}
}
